package com.zy.datareceiver.binsess.stomp.conf;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.*;

/**
 * webSocket配置
 */
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfiguration extends AbstractWebSocketMessageBrokerConfigurer  {
    private static final Logger log = LoggerFactory.getLogger(WebSocketConfiguration.class);

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        //将clientMessage注册为STOMP的一个端点
        //客户端在订阅或发布消息到目的路径前，要连接该端点
        //setAllowedOrigins允许所有域连接，否则浏览器可能报403错误
        registry.addEndpoint("/stompwebsocket").setAllowedOrigins("*").withSockJS();

    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/queue", "/topic");
        //后台应用接收浏览器消息端点前缀，这个将直接路由到@MessageMapping上
        config.setApplicationDestinationPrefixes("/app");
    }
}
